/**
 *
 * Created by ChengXiancheng on 2016/12/11.
 */

/**
 *
 * @param ctx 绘制上下文
 * @param number 小圆个个数
 * @param circleX 大圆的x轴
 * @param circleY 大圆的y轴
 * @param circleRadius 大圆的半径
 * @param circleRadius 小圆的半径
 * @constructor
 */
function Chain(opts){
    this.smallRadius=5;
    this.smallColor="black";

    //混入继承
    for (var key in opts) {
        this[key]=opts[key];
    }

    this.init();
}
Chain.prototype={
    constructor:Chain,
    init:function(){
        //绘制小圆
        this.drawBigCircle();
        //绘制大圆
        this.drawSmallCircle();
    },
    /**
     * 绘制大圆
     */
    drawBigCircle:function(){
        this.ctx.beginPath();
        this.ctx.strokeStyle="lightgray";
        this.ctx.arc(this.circleX,this.circleY,this.circleRadius,0,2*Math.PI);
        this.ctx.stroke();
    },
    /**
     * 绘制小圆
     */
    drawSmallCircle:function(){
        var singleRadius=2*Math.PI/this.number;
        var startRadius=0;

        for (var i = 0; i < this.number; i++,startRadius+=singleRadius) {
            this.ctx.beginPath();
            var y1=this.circleY-this.circleRadius*Math.sin(startRadius);
            var x1=this.circleX+this.circleRadius*Math.cos(startRadius);

            this.ctx.arc(x1,y1,this.smallRadius,0,2*Math.PI);
            this.ctx.fillStyle=this.smallColor;
            this.ctx.fill();
        }
    }
}